const path = require('path')
const PrerenderSPAPlugin = require('prerender-spa-plugin')
const Renderer = PrerenderSPAPlugin.PuppeteerRenderer

module.exports = {
  lintOnSave: false,
  productionSourceMap: false,
  publicPath: '/',
  assetsDir: 'static',
  devServer:{
    open: true,
    hot: true,
    disableHostCheck: true
  },
  chainWebpack: config => {
    config.plugin('html').tap(args => {
      args[0].title= '检查链接'
      return args
    })
  },
  configureWebpack(config) {
    if (process.env.NODE_ENV === 'production') {
      const prerenderCfg = new PrerenderSPAPlugin({
        indexPath: path.join(__dirname, 'dist', 'index.html'),
        staticDir: path.join(__dirname, 'dist'),
        outputDir: path.join(__dirname, 'dist', 'pages'),
        routes: ['/', '/product', '/about', '/help'],
        renderer: new Renderer({ renderAfterDocumentEvent: 'prerender' })
      })
      config.plugins.push(prerenderCfg)
    }
  },
  pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'less',
      // 引入需要全局加载的 less 文件
      patterns: [path.resolve(__dirname, './src/assets/less/variable.less')],
    },
  }
}
